"""
__author__ = '霍格沃兹测试开发学社'
__desc__ = '更多测试开发技术探讨，请访问：https://ceshiren.com/t/topic/15860'
"""

from dataclasses import dataclass, field
from datetime import datetime
from typing import List

from sqlalchemy import *
from sqlalchemy.orm import relationship

# from orm_domain import project_testcase_rel, Testcase, Execution, Job
from orm_domain.execution import Execution
from orm_domain.job import Job
from server import mapper_registry


@mapper_registry.mapped
@dataclass
class ResultFormatter:
    __tablename__ = "result_formatter"
    __sa_dataclass_metadata_key__ = "sa"

    id: int = field(init=False, metadata={"sa": Column(Integer, primary_key=True)}, )
    execution_obj: Execution = field(init=False,
                                     metadata={"sa": relationship("Execution", backref="result_formatter")}, )
    job_obj: Job = field(init=False, metadata={"sa": relationship("Job", backref="result_formatter")}, )
    execution_id: int = field(default=None, metadata={"sa": Column(Integer, ForeignKey('execution.id'))}, )
    job_id: int = field(default=None, metadata={"sa": Column(Integer, ForeignKey("job.id"))}, )
    data: str = field(default=None, metadata={"sa": Column(TEXT)}, )
    create_time: datetime = field(init=False,
                                  metadata={"sa": Column(DateTime, nullable=True, default=datetime.now)}, )
